package com.zp.game

import com.helloandroid.AppUtil
import com.helloandroid.vo.IDeepCopy


//  转盘信息
data class ZhuanPanInfo(
        var resetCount:Int, // 剩余次数
        var usedCount:Int, // 累计已抽奖次数,不是每日更新
        var awardStateLst:ArrayList<Int>, // 奖励 item的领取状态
        var iphone12Pro:Int, //   碎片个数
        var hwMate40:Int,
        var xiaomi10:Int,
        var oppoX:Int,
        var vivoX60:Int): IDeepCopy<ZhuanPanInfo> {

    companion object{
        const val Iphone12Pro = 1
        const val HwMate40Pro = 2
        const val XiaoMi10Pro = 3
        const val OppoX = 4
        const val VivoX60 = 5
        const val BigCoin = 6
        const val MidCoin = 7
        const val SmallCoin = 8
    }

    override fun deepCopy(): ZhuanPanInfo {
        val newAwardList = ArrayList<Int>()
        awardStateLst.forEach {
            newAwardList.add(it)
        }
        return ZhuanPanInfo(resetCount, usedCount, newAwardList, iphone12Pro, hwMate40, xiaomi10, oppoX, vivoX60)
    }

    fun increase(awardId:Int,count:Int){
        usedCount++
        resetCount--
        when(awardId){
            Iphone12Pro -> iphone12Pro += count
            HwMate40Pro -> hwMate40 += count
            XiaoMi10Pro -> xiaomi10 += count
            OppoX -> oppoX += count
            VivoX60 -> vivoX60 += count
            BigCoin,
            MidCoin,
            SmallCoin -> AppUtil.increaseCoin(count)
        }
    }

    fun updateAwardState(idx:Int,newState:Int){
        awardStateLst[idx] = newState
        checkReset()
    }

    private fun checkReset(){
        val sum = awardStateLst.fold(0){acc,v->
            acc + v
        }
        if (sum == 3){
            for (i in awardStateLst.indices){
                awardStateLst[i] = 0
            }
            usedCount = 0
        }
    }
}